/* Simple ESP32C3 Test Program */

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

/* LED GPIO pin */
#define LED_PIN GPIO_NUM_2

/* LED blink interval in milliseconds */
#define LED_BLINK_INTERVAL_MS 1000

/* Task priorities */
#define MAIN_TASK_PRIORITY 5
#define LED_TASK_PRIORITY 3

/* LED blink task */
static void led_blink_task(void *arg)
{
    printf("LED blink task started\n");
    
    /* Configure LED pin as output */
    gpio_reset_pin(LED_PIN);
    gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
    
    while (1) {
        /* Toggle LED */
        gpio_set_level(LED_PIN, 1);
        vTaskDelay(LED_BLINK_INTERVAL_MS / portTICK_PERIOD_MS);
        
        gpio_set_level(LED_PIN, 0);
        vTaskDelay(LED_BLINK_INTERVAL_MS / portTICK_PERIOD_MS);
    }
}

/* Main task */
void app_main(void)
{
    printf("Hello from ESP32C3 FreeRTOS Project!\n");
    printf("System starting...\n");
    
    /* Create LED blink task */
    xTaskCreate(led_blink_task, "led_blink_task", 1024, NULL, LED_TASK_PRIORITY, NULL);
    
    printf("Main task completed, system running...\n");
}
